﻿using System.Windows;

namespace DeskRedis.MyControl.UserControls
{
    /// <summary>
    /// WinLoading.xaml 的交互逻辑
    /// </summary>
    public partial class WinLoading : Window
    {
        private static WinLoading loading;

        public WinLoading()
        {
            this.InitializeComponent();

            if (this.Owner == null)
            {
                this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }
            else
            {
                loading.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            }
        }

        /// <summary>
        /// 显示加载动画。
        /// </summary>
        /// <param name="text">提示文本。</param>
        public static void Loading(string text)
        {
            loading = CreateLoading();
            loading.tblockContent.Text = text;
            loading.Show();
        }

        public static void Loading(string text, Window owner)
        {
            loading = CreateLoading();
            loading.Owner = owner;
            loading.WindowStartupLocation = WindowStartupLocation.CenterOwner;

            loading.tblockContent.Text = text;
            loading.Show();
        }

        /// <summary>
        /// 关闭加载动画。
        /// </summary>
        public static void CloseLoading()
        {
            loading.Close();
            loading = null;
        }


        #region 私有方法
        private static WinLoading CreateLoading()
        {
            if (loading == null)
            {
                loading = new WinLoading();
            }
            return loading;
        }
        #endregion
    }
}
